package org.ufinity.hsms.module.device.command;

import java.util.List;

import org.json.JSONObject;
import org.ufinity.hsms.common.command.AbstractCommand;
import org.ufinity.hsms.common.impl.GetDateImpl;
import org.ufinity.hsms.module.device.entity.HostGroupEntity;

 /**
 * @Description 获主机组列表
 * @author 钱新才
 */
public class HostGroupCommand extends AbstractCommand<JSONObject> {
	
	boolean isTriger = false;
	public HostGroupCommand(boolean isTriger) {
		this.isTriger = isTriger;
	}

	@Override
	public JSONObject execute() throws Exception {
		if(isTriger){
			JSONObject json = GetDateImpl.getHostGroup();
			if(json!=null && !json.isNull("result")){
				String result = json.getString("result");
				List<HostGroupEntity> list = HostGroupEntity.getList(result);
				if(list!=null && list.size()>0){
					int size = list.size();
					String hostId = "";
					for(int i = 0;i<size;i++){
						if(i == 0){
							hostId = list.get(i).getGroupid();
						}else{
							hostId = hostId + "," + list.get(i).getGroupid();
						}
					}
					return GetDateImpl.getTrigger(hostId);
				}
			}
		}else{
			return GetDateImpl.getHostGroup();
		}
		return null;
	}

}
